#include<bits/stdc++.h>
using namespace std;
namespace IO{
    const int BUF=1<<21;
    char buff[BUF],*p1=buff,*p2=buff;
    #define gc() (p1==p2&&(p2=((p1=buff)+fread(buff,1,BUF,stdin)),p1==p2)?EOF:*p1++)
    template<typename T>inline void read(T &x){
        char ch=gc();x=0;int f=1;
        while(!isdigit(ch)){if(ch=='-')f=-1;ch=gc();}
        while(isdigit(ch)) x=(x<<1)+(x<<3)+(ch^48),ch=gc();
        x*=f;
    }
    char obuf[BUF],*p3=obuf;
    inline void pc(char ch){
        if(p3-obuf<BUF) *p3++=ch;
        else fwrite(obuf,p3-obuf,1,stdout),p3=obuf,*p3++=ch;
    }
    inline void put(const char *s){while(*s) pc(*s),++s;}
    char ch[32],ctop;
    template<typename T>inline void print(T x){
    	if(x<0) x=~x+1,pc('-');
        if(!x) return pc(48);
        while(x) ch[++ctop]=x%10^48,x/=10;
        while(ctop) pc(ch[ctop--]);
    }
    inline void flush(){fwrite(obuf,p3-obuf,1,stdout);p3=obuf;}
}
using namespace IO;
const int N=1e6+5,mod=6661;
#define ll long long
int n,m,C[mod][mod],sum[mod][mod];
inline int c(int x,int y){
	if(y<0) return 0;
	return (sum[x][x]*(y/mod)+sum[x][min(x,y%mod)])%mod;
}
inline int Lucus(ll x,int l,int r){
	const int x1=x%mod,x2=x/mod%mod;
	int ans=0,pre=c(x1,l-1),now;
	for(int i=l,rt,w=l/mod;i<=r;i=rt+1,++w){
		rt=min(r,(w+1)*mod-1);
		now=(sum[x1][x1]*w+sum[x1][min(rt%mod,x1)])%mod;
		(ans+=(now-pre)*C[x2][w])%=mod;
		pre=now;
	}
	return (ans+mod)%mod;
}
int res[N<<3],idx;
struct node{
	int l,r,s,id;
	ll x;
	inline bool operator<(node y)const{return r<y.r;}
};
set<node> S;
inline auto split(int x,bool op){
	if(x>n) return S.end();
	auto it=S.lower_bound((node){0,x,0,0,0});
	if((it->l)==x) return it;
	node v=*it;S.erase(it);
	S.insert((node){v.l,x-1,v.s,++idx,v.x});
	return S.insert((node){x,v.r,v.s+x-v.l,++idx,v.x}).first;
}
inline void change(ll x,int l,int r){
	auto rt=split(r+1,1),lt=split(l,0);
	S.erase(lt,rt);
	S.insert((node){l,r,1,++idx,x});
}
inline int query(int l,int r){
	int ans=0;
	for(auto it=S.lower_bound((node){0,l,0,0,0});it!=S.end()&&(it->l)<=r;++it){
		node v=*it;
		if(l<=v.l&&v.r<=r){
			if(res[v.id]<0) res[v.id]=Lucus(v.x,v.s,v.s+v.r-v.l);
			(ans+=res[v.id])%=mod;
		}else (ans+=Lucus(v.x,v.s+max(0,l-v.l),v.s+min(r,v.r)-v.l))%=mod;
	}
	return ans;
}
int main(){
	freopen("izumi.in","r",stdin);
	freopen("izumi.out","w",stdout);
	for(int i=C[0][0]=1;i<mod;++i)
	for(int j=C[i][0]=1;j<=i;++j) C[i][j]=(C[i-1][j]+C[i-1][j-1])%mod;
	for(int i=0;i<mod;++i){
		sum[i][0]=1;
		for(int j=1;j<=i;++j) sum[i][j]=(sum[i][j-1]+C[i][j])%mod;
	}
	memset(res,-1,sizeof(res));
	ll kx;
	read(n),read(m),read(kx);
	S.insert((node){1,n,1,Lucus(kx,1,n),kx});
	while(m--){
		int op,l,r;
		read(op),read(l),read(r);
		if(op==1){
			ll x;read(x);
			change(x,l,r);
		}else{
			print(query(l,r)),pc('\n');
		}
	}
	flush();
	return 0;
}
